//
//  LoginModel.swift
//  E-CycleForShop
//
//  Created by enghou on 17/3/1.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit

class LoginModel: BaseModel {
    var number = ""
    var name = "" //存储门店地址
    var account = ""
    var province = ""
    var city = ""
    var area = ""
    var kind = 0
    var blance : Int = 0 //应该是盈利
    var token = "" //token
    var id = -1
    var hall_id = -1
    override init(source sourceDt: Dictionary<String, Any>?) {
        super.init(source: sourceDt)
        
        let result = data as? Dictionary<String,Any>
        
        guard result != nil else {
            return
        }
        
        if let tok = result!["token"] as? String {
            token = tok
        }
        
        if let jsobj = result!["businessHallUser"] as? Dictionary<String,Any>{
            if let businessHallId = jsobj["businessHallId"] as? Int {
                hall_id = businessHallId
            }
            
            if let num = jsobj["number"] as? String {
                number = num
            }
            if let nam = jsobj["name"] as? String {
                name = nam
            }
            if let accoun = jsobj["account"] as? String {
                account = accoun
            }
            if let channelOrg = jsobj["channelOrg"] as? Dictionary<String,Any> {
                if let provin = channelOrg["province"] as? Int{
                    province = String(provin)
                }
                if let ci = channelOrg["city"] as? Int {
                    city = String(ci)
                }
                if let are = channelOrg["area"] as? Int {
                    area = String(are)
                }
                if let kin = jsobj["kind"] as? Int {
                    kind = kin
                }
            }
            if let i = jsobj["id"] as? Int {
                id = i
            }
            if let blanc = jsobj["blance"] as? Int{
                blance = blanc
            }
        }
    }
    
    func saveToLocal() -> Void {
        DataCacher.shared().saveModel(model: self)
    }
}
